/*
********************************************************************************
* Copyright (C) 2021, xiang.D <dx_65535@163.com>.
* All right reserved.
*
* File Name   : led_manager.cc
* Author      :
* Version     : V1.0
* Description :
* Journal     : 2022-02-13 init v1.0
* Brief       : Blog: https://blog.csdn.net/qq_38750572?spm=1001.2014.3001.5343
* Others      :
********************************************************************************
*/
#include <stdio.h>
#include "msg_manager.h"
#include "led_manager.h"

#define LOGI(fmt, args...) printf(fmt, ##args)
#define LOGD(fmt, args...) //printf("%d LedManager D: " fmt, __LINE__, ##args)
#define LOGW(fmt, args...) printf("%d LedManager W: " fmt, __LINE__, ##args)
#define LOGE(fmt, args...) printf("%d LedManager E: " fmt, __LINE__, ##args)

CLedManager::CLedManager()
{

}

CLedManager::~CLedManager()
{

}

CLedManager* CLedManager::GetInstance()
{
    static CLedManager Obj;
    return &Obj;
}

void CLedManager::Init()
{
    SetListener(CLedManager::SendMsg);
}

void CLedManager::SendMsg(int type, void* msg)
{
    LOGD("Send: 0x%x \n", type);
    CLedManager::GetInstance()->ProcessMsg((ELedMsgType)type, msg);
}

void CLedManager::ProcessMsg(ELedMsgType type, void* msg)
{
    LOGD("Recv: 0x%x \n", type);

    switch(type)
    {
        case LED_OPEN:
        {
            int index = -1;

            if (msg) {
                index = *(int *)msg;
                OpenLight(index);
            }

            break;
        }

        case LED_STOP:
        {
            int index = -1;

            if (msg) {
                index = *(int *)msg;
                Stop(index);
            }

            break;
        }

        case LED_HORSE:
        {
            int index = -1;

            if (msg) {
                index = *(int *)msg;
                ShowHorseLight(index);
            }

            break;
        }

        case LED_BREATH:
        {
            int index = -1;

            if (msg) {
                index = *(int *)msg;
                ShowBreathLight(index);
            }

            break;
        }

        default:
            LOGW("No type 0x%x\n", type);
        break;
    }
}

void CLedManager::ShowHorseLight(int index)
{
    LOGI("Led[%d] horse light.\n", index);
}

void CLedManager::ShowBreathLight(int index)
{
    LOGI("Led[%d] breath light.\n", index);
}

void CLedManager::OpenLight(int index)
{
    LOGI("Led[%d] light open.\n", index);
}

void CLedManager::Stop(int index)
{
    LOGI("Led[%d] light close.\n", index);
}
